from graphics import GraphWin

# 数据
def line(x1,x2, y1,y2):
    length = abs(y2-y1) if abs(y2-y1)>=abs(x2-x1) else abs(x2-x1)
    length *= 5
    delta_x = (x2-x1)/length; delta_y = (y2-y1)/length
    k = 1
    x = x1; y = y1
    pts = []
    while k <= length+1:
        pts.append((x, y))
        k += 1
        x += delta_x; y += delta_y
    return pts

pts = line(0,200, 126,60)

win = GraphWin("直线", 400,400)

for pt in pts:
    win.plotPixel(*pt, color="black")

#等待鼠标响应，退出程序
win.getMouse()
win.close()

